//
//  MainViewController.swift
//  sinaOnceAgain
//
//  Created by 王相超 on 16/2/16.
//  Copyright © 2016年 chuanzhi. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    
    //点击事件
    @objc private func plusBtnDidClick() {
        
       let compose = ComposeViewController()
        
        //包到导航控制器中
        let nav = BaseNavigationController(rootViewController:compose)
        presentViewController(nav, animated: true, completion: nil)
    }
    
    //相当于控制器的入口
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabbar = MainTabbar()
        
        setValue(mainTabbar, forKey: "tabBar")
        
        mainTabbar.plusBtn.addTarget(self, action: "plusBtnDidClick", forControlEvents: .TouchUpInside)
        

       addchildviewcontrollers()
    }

   
    private func addchildviewcontrollers() {
        
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
    }
    
    
    
    
    //添加单个视图控制器
    private func addChildViewController(vc: UIViewController, title: String, imageName: String) {
        
        //设置渲染颜色
        tabBar.tintColor = UIColor.orangeColor()
        
        let nav = BaseNavigationController(rootViewController: vc)
        
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        
        addChildViewController(nav)
    }
    
    
}
